Applying search parameters based on the query using Rules.
aroundLatLngViaIP
, are available at query time, you can use rules to detect a search for a specific city or country and change search parameters on the fly.
nb_airline_liaisons
for custom ranking to prioritize airports with many liaisons.
Yet, as soon as aroundLatLngViaIP
is set to true
in your search code, this custom ranking would be overridden in favor of geographical proximity, which is part of ranking formula.
In other words, you would still have the Paris problem because Le Bourget, even if it has the lowest number of liaisons, has the closest geographical proximity to the user.
Other examples: if a user is in Paris and searches for “israel”, they would first get Haifa airport, because this is the Israeli airport that’s the closest to Paris. Yet, it wouldn’t make sense, as Haifa airport is relatively small. “Ben Gurion” is a better choice. Same goes if they were looking for “shanghai”. Hongqiao airport is geographically closer to Paris, but not as big as Pudong airport, which is only 30 km away from Hongqiao.
Fix this by creating a rule that detects searches for a specific city or country and turns off aroundLatLngViaIP
as a consequence.
Whenever a user specifically looks for a city or country name, like “paris”, “israel”, or “shanghai”, the distance-based search would be turned off, falling back on custom ranking by number of liaisons.
nb_airline_liaisons
for custom ranking. You also need to set city
and country
as attributes for faceting, so you can detect whenever a query matches any of them.
city
and country
, and changes the search parameters accordingly. For this, you need to use the batchRules
method.
nb_airline_liaisons
attribute from the drop-down menu.country
and city
attributes from the drop-down menu.{facet:country}
should then be displayed in the input.
{ "aroundLatLngViaIP": false }
{facet:city}
should then be displayed in the input.
{ "aroundLatLngViaIP": false }
aroundLatLngViaIP
to false
regardless of the parameters you set in the query.
Therefore, when a user searches for “paris” or “china”, matching airports are ranked by nb_airline_liaisons
.
When not searching for either a city or a country, airports are ranked by distance to a user’s current location.